package com.agent.vpsserver.common.handler;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.function.Supplier;

/**
 * @Author: gc
 * @Date: 2022/6/5
 * @Description:
 **/
@Component
public class TransactionHandler {

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public <T> T runInTransaction(Supplier<T> supplier) {
        return supplier.get();
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor = Exception.class)
    public <T> T runInNewTransaction(Supplier<T> supplier) {
        return supplier.get();
    }
}
